<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $blogsModel = D('blogs');//实例化blogs表
        $blogs = $blogsModel->select();//显示
        
        $this->assign('data',$blogs);//模板赋值
        
        $this->display();
    }

     //删除
    public function del($id){
        $blogs = M('blogs');
        if($blogs->delete($id)){
            $this->redirect('Index/index');
        }else{
            exit($blogs->getError());
        }
        
    }

    //编辑
    public function update($id){
        $blogs = M('blogs');

        if(empty($_POST)){
            $data = $blogs->find($id);
            $this->assign('data',$data);
            $this->display();
        }else{
            $blogs->create();
            $blogs->save();
            $this->redirect('Index/index');
        }
    }


    public function title($id){
        $blogsModel = M('blogs');
        $data = $blogsModel->find($id);
        // var_dump($data);
        // exit;
        $this->assign('data',$data);
        $this->display();
    }
}